#include <iostream>
#include <string>
using namespace std;

int symbolValues(char c) {
    if(c=='I')
        return 1;
    else if(c=='V')
        return 5;
    else if(c=='X')
        return 10;
    else if(c=='L')
        return 50;
    else if(c=='C')
        return 100;
    else if(c=='D')
        return 500;
    else if(c=='M')
        return 1000;
    else
        return 0;
};

int romanToInt(string s) {
    int ans = 0;
    int n = s.length();
    for (int i = 0; i < n; i++) {
        int value = symbolValues(s[i]);
        if (i < n - 1 && value < symbolValues(s[i+1])) {
            ans -= value;
        } else {
            ans += value;
        }
    }
    return ans;
}



int main(){
    int res = romanToInt("LVIII");
    cout<<res<<endl;
  return 0;
}
